package tms

import (
    "encoding/json"

    cecClient "git.inspur.com/cec/nats-sdk-go"
    eventsV2 "github.com/cloudevents/sdk-go/v2"
)

func SendDeleteTagEvent(a5tId string, tag Tag) error {
    return NewAndSend(a5tId, ResourceECI, ActionDelete, tag)
}

func NewAndSend(a5tId, resource, action string, jsonObj interface{}) error {
    logger.Info("tms send event: %v", a5tId)
    event, err := NewEvent(a5tId, resource, action, jsonObj)
    if err != nil {
        return err
    }
    return Send(event)
}

func Send(event *eventsV2.Event) error {
    bs, err := json.Marshal(event)
    if err != nil {
        _ = logger.Error("tms send event error: %v")
    }
    logger.Info("tms send event: %v", string(bs))
    return cecClient.Publish(*event)
}
